package com.作业.Day12;

import java.util.ArrayList;
import java.util.Iterator;

public class Homework4 {
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        arrayList.add("1111");
        arrayList.add("1111");
        arrayList.add("2222");
        arrayList.add("2222");
        arrayList.add(new Student("张三", 18));
        arrayList.add(new Student("张三", 18));
        System.out.println("去重前遍历");
        for (Object o : arrayList) {
            System.out.println(o);
        }
        /**
         *1. 创建迭代器遍历
         *2. 创建一个新的集合去收集数据
         *3. 判断新的集合里面是否存在数据·
         *4. 如果没有插入数据
         */
        Iterator iterator = arrayList.iterator();
        ArrayList<Object> objects = new ArrayList<>();
        while (iterator.hasNext()) {
            Object next = iterator.next();
            if(!objects.contains( next)){
                objects.add(next);
            }
        }
        System.out.println("去重后遍历");
    }
}
